import { Module } from "@nestjs/common";
import { ConfigModule, ConfigService } from "@nestjs/config";
import { AccountsModule } from "@/accounts";
import { CryptoModule } from "@/crypto";
import typeorm from "@/config/typeorm";
import { TypeOrmModule } from "@nestjs/typeorm";
import { AutomapperModule } from "@automapper/nestjs";
import { classes } from "@automapper/classes";
import { S3Module } from "nestjs-s3";
import { ScheduleModule } from "@nestjs/schedule";
import { CommandModule } from "nestjs-command";

@Module({
    imports: [
        ConfigModule.forRoot({
            isGlobal: true,
            load: [typeorm]
        }),
        TypeOrmModule.forRootAsync({
            imports: [ConfigModule],
            useFactory: (configService: ConfigService) => configService.get("typeorm"),
            inject: [ConfigService]
        }),
        AutomapperModule.forRoot({
            strategyInitializer: classes()
        }),
        S3Module.forRootAsync({
            imports: [ConfigModule],
            useFactory: async (configService: ConfigService) => ({
                config: {
                    accessKeyId: configService.get<string>("S3_ACCESS_KEY"),
                    secretAccessKey: configService.get<string>("S3_SECRET_KEY"),
                    endpoint: configService.get<string>("S3_SERVER_URL"),
                    s3ForcePathStyle: true,
                    signatureVersion: "v4"
                }
            }),
            inject: [ConfigService]
        }),
        ScheduleModule.forRoot(),
        CommandModule,
        AccountsModule,
        CryptoModule
    ],
    controllers: [],
    providers: []
})
export class AppModule {}
